package com.blog.service.Impl;

import com.blog.service.EmailService;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * @author cgx
 * @Date 2021/8/18 12:08
 */
@Service
public class EmailServiceImpl implements EmailService, Serializable {

    @Resource
    JavaMailSender mailSender;

    /**
     * 邮箱发送验证码服务
     * @param
     * @return
     */
    @Override
    public void sendEmail(String registerCode,String sendTo) {
        SimpleMailMessage message = new SimpleMailMessage();
        //发送人邮箱
        message.setFrom("495390834@qq.com");
        //发送给谁    对方邮箱
        message.setTo(sendTo);
        //标题
        message.setSubject("欢迎用户使用gxcc3博客系统：");
        //内容
        message.setText("尊敬的用户您好，您本次的验证码为 : "+registerCode+"\n验证码30分钟内有效\n"+
                        "Dear user, your verification code this time is : "+registerCode+"\nThe verification code is valid within 30 minutes");
        //发送
        mailSender.send(message);
    }

    @Override
    public void lockUserTellAdmin(String lockUserName, String sendTo) {
        SimpleMailMessage message = new SimpleMailMessage();
        //发送人邮箱
        message.setFrom("495390834@qq.com");
        //发送给谁    对方邮箱
        message.setTo(sendTo);
        //标题
        message.setSubject("欢迎用户使用gxcc3博客系统：");
        //内容
        message.setText("用户： "+lockUserName+"\n多次进行xss注入，已被锁定，请知悉\n");
        //发送
        mailSender.send(message);
    }

}
